package com.example.community.dao;

import com.example.community.mapper.ParkingMapper;
import com.example.community.mapper.PaymanagerMapper;
import com.example.community.mapper.PaytypeMapper;
import com.example.community.model.Parking;
import com.example.community.model.Paymanager;
import com.example.community.model.Paytype;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 车位表
 */
public class ParkingDao {
    public Parking fandById(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            return mapper.selectByPrimaryKey(id);
        }
    }


    public List<Parking> fandByAll(){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            return mapper.selectAll();
        }
    }

    public int selectPno(Integer usNo){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            return mapper.selectPno(usNo);
        }
    }

    public List<Parking> selectNull(){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            return mapper.selectNull();
        }
    }

    public Integer update(Parking users){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            int i = mapper.updateByPrimaryKey(users);
            session.commit();
            return i;
        }
    }

    public List<Parking> fandLimit(Integer ys, Integer shuju){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            Integer yss =(ys - 1) * shuju;
            return mapper.selectLimit(yss,shuju);
        }
    }

    public Integer selectLimitCount(Integer pageSize){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            int count = mapper.CountParking();
            return (count + pageSize - 1)/pageSize;
        }
    }

    public Integer insert(Parking parking){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            int i = mapper.insert(parking);
            session.commit();
            return i;
        }
    }

    public Integer delete(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final ParkingMapper mapper = session.getMapper(ParkingMapper.class);
            int i = mapper.deleteByPrimaryKey(id);
            session.commit();
            return i;
        }
    }
}
